package com.didispace.chapter36.listener;

import com.didispace.chapter36.entity.User;
import com.didispace.chapter36.mapper.UserMapper;
import com.didispace.chapter36.service.UserRegisterEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

import java.util.List;

/**
 * @author mrzha
 */
@Component
@Slf4j
public class UserListener {
    @Autowired
    private UserMapper userMapper;
    @Async
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, classes = UserRegisterEvent.class)
    public void onUserRegisterEvent(UserRegisterEvent event) {
        log.info("开始查询");
        // 根据姓名查询
        List<User> user = userMapper.findByName("李春天");
        log.info(user.toString());
    }
}
